<?PHP
$PurviewLevel=0;
ob_start();  
require("../../inc/common.inc.php");
ob_end_clean();
require_once(dirname(__FILE__)."/../"."Admin_ChkPurview.php");
/**
*处理添加新消息

图文消息暂时还不能保存到素材库
**/
if($action=="saveadd"){
$vppuserstr="";
if(isset($_COOKIE["vppusers"])){
	$vppuserstr = $_COOKIE["vppusers"];
}
if ($ttitle=="" || empty($ttitle)){
	$fun->popmassage("信息标题不能为空","","popback");
	exit();
}
$ttype = intval($ttype);
$tsucaiid = intval($tsucaiid);
$tmsgid = intval($tmsgid);
$issave = intval($issave);
if($ttype==1){
	$tcontent = $tcontent1;
	if ($tcontent=="" || empty($tcontent)){
	$fun->popmassage("请设置消息的内容","","popback");
	exit();
	}
}elseif ($ttype==5){
	$tcontent = $tcontent5;
	$tpath = $tpath5;
	if($tpath==""){
	$fun->popmassage("请设置消息的封面","","popback");
	exit();
	}
	if($tcontent==""){
	$fun->popmassage("请设置消息的内容","","popback");
	exit();
	}
}elseif ($ttype==4){
	$tcontent = $tabstract4;
	$tpath = $tpath4;
	if($tpic==""){
	$fun->popmassage("请设置视频的封面","","popback");
	exit();
	}
	if($tpath==""){
	$fun->popmassage("请先上传视频文件","","popback");
	exit();
	}
	if($tcontent==""){
	$fun->popmassage("请设置视频的简介","","popback");
	exit();
	}
}elseif($ttype==3){
	$tcontent = $tabstract3;
	$tpath = $tpath3;
	if($tpath==""){
	$fun->popmassage("请先上传图片文件","","popback");
	exit();
	}
	if($tcontent==""){
	$fun->popmassage("请设置图片的简介","","popback");
	exit();
	}
}elseif($ttype==2){
	$tcontent = $tabstract2;
	$tpath = $tpath2;
	if($tpath==""){
	$fun->popmassage("请先上传语音文件","","popback");
	exit();
	}
	if($tcontent==""){
	$fun->popmassage("请设置语音的简介","","popback");
	exit();
	}
}

$addtime = mktime();
switch($ttype){
	case 2;$ftype=3;break;
	case 3;$ftype=2;break;
	case 4;$ftype=4;break;
}
if($issave==1){
		$db->excu("insert into mx_sucai_file (`fname`,`fpath`,`fsize`,`ftype`,`fpic`,`fintro`,`addtime`,`addid`,`isok`) values ('$ttitle','$tpath','$filesize','$ftype','$tpic','$tcontent','$addtime','".$_SESSION['mxadmin']['userid']."','1')");
}


$tgroupid=intval($tgroupid);
$tsex=intval($tsex);
$truepath=preg_replace("/(.+)\/([^\/]+)\/([^\/]+)/is","\\1",'http://'.$HTTP_HOST.$PHP_SELF);
$tcontent=str_replace($truepath,"",$tcontent);
$tcontent=str_replace("﹪","%",$tcontent);
$tcontent=mysql_escape_string($tcontent);
		
$db->excu("INSERT INTO `mx_tuisong_vpp` ( `ttitle`, `ttype`,`tcontent`,`tsucaiid`,`tmsgid`,`tuserids`,`tgroupid`,`tsex`,`tprovince`,`tcity`,`tarea`,`addtime`,`addid`) VALUES ('$ttitle','$ttype','$tcontent','$tsucaiid','$tmsgid','$vppuserstr','$tgroupid','$tsex','$province','$city','$area','$addtime','".$_SESSION['mxadmin']['userid']."')");
$tid = mysql_insert_id();

setcookie("vppusers","",time()-3600);
setcookie("vppusersnum","0",time()-3600);

if($vppuserstr!=""){
	$vppuserstr = substr($vppuserstr,0,strlen($vppuserstr)-1);
	$vppuserarr = split(",",$vppuserstr);
	foreach($vppuserarr as $key => $value){
		$db->excu("INSERT INTO `mx_tuisong_vpp_log` ( `tid`, `userid`,`viewtype`,`addtime`) VALUES ('$tid','".$value."','0','$addtime')");
	}
}else{
$wherestr="isok=1";
if($tprovince!=""){
$wherestr .= "and province like '%$tprovince%'";
}
if($tcity!=""){
$wherestr .= "and city like '%$tcity%'";
}
if($tarea!=""){
$wherestr .= "and district like '%$tarea%'";
}
if($tgroupid!=0){
	$wherestr.=" and groupid='$tgroupid'";
}
if($tsex!=2){
	$wherestr.=" and sex='$tsex'";
}
$userquery = $db->excu("select * from mx_user where ".$wherestr);
$userinfo = array();
if ($db->num_rows($userquery)>0){
	while($userarr = $db->fetch_array($userquery)){
		$userinfo[] = $userarr;
	}
}
if(count($userinfo)==0){
	$db->excu("delete from `mx_tuisong_vpp` where `tid`='$tid'");
	$fun->popmassage("您设置的条件未找到符合要求的用户","","popback");
	exit();
}else{
	foreach($userinfo as $key=>$value){
		$db->excu("INSERT INTO `mx_tuisong_vpp_log` ( `tid`, `userid`,`viewtype`,`addtime`) VALUES ('$tid','".$value["id"]."','0','$addtime')");
	}
}
}

jump2("操作成功","tuisong_vpp_list.php",2);
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>铭讯EOS网站后台管理</TITLE>
<Meta name="Keywords" Content="济南网站建设 济南网站制作 山东网站建设 济南铭讯软件有限公司">
<Meta name="Description" Content="济南网站制作：铭讯软件专业服务优秀企业，致力于网站建、设网站推广、网络营销一体的全访位网络服务商">
<link href="../images/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php require("../mx_head.php") ;

?>

	<!--right-->
	<div class="right">
	  
		<div class="xm2">
			<h1 class="fl">新建推送</h1>
			<!--<span class="fr"><a href="#"><img src="../images/right_4.png" alt="设置" /></a></span>-->
			<div class="clear"></div>
		</div>
		<div class="xm2_b">
			<div class="height15"></div>
				<script type="text/javascript" src="../js/jquerys-1.5.1.js"></script>
                <script type="text/javascript" src="../js/pcasunzip.js"></script>
                <script type="text/javascript" src="../js/tuisong.js"></script>
				<script language="javascript">
				$(document).ready(function(){ //这个就是传说的ready   
				$(".stripe tr").mouseover(function(){   
				//如果鼠标移到class为stripe的表格的tr上时，执行函数   
				$(this).addClass("over");}).mouseout(function(){   
				//给这行添加class值为over，并且当鼠标一出该行时执行函数   
				$(this).removeClass("over");}) //移除该行的class   
				$(".stripe tr:even").addClass("alt");   
				//给class为stripe的表格的偶数行添加class值为alt
				//www.divcss5.com 整理特效
				});  
				function showinfo(returnid,changeid,changevalue){
					document.getElementById(changeid).value=changevalue;
					$.ajax({ url: "getinfo3.php?id="+changevalue+"&cid="+changeid,dataType: "json",success: function(msg){
					  if(msg.cid=="tmsgid"){
						
							document.getElementById("ttitle").value=msg.mtitle;
							document.getElementById("tpath5").value=msg.mpic;
							editor.html(msg.mcontent);
							document.getElementById("tcontent5").value=msg.mcontent;
						
					  }else if(msg.ftype==2){
						  document.getElementById("ttitle").value=msg.fname;
						  document.getElementById("tpath3").value=msg.fpath;
						  document.getElementById("tabstract3").value=msg.fintro;
					  }else if(msg.ftype==3){
						  document.getElementById("ttitle").value=msg.fname;
						  document.getElementById("tpath2").value=msg.fpath;
						  document.getElementById("tabstract2").value=msg.fintro;
					  }else if(msg.ftype==4){
						  document.getElementById("ttitle").value=msg.fname;
						  document.getElementById("tpath4").value=msg.fpath;
						  document.getElementById("tpic").value=msg.fpic;
						  document.getElementById("tabstract4").value=msg.fintro;
						  
					  }
					}});

					
				}
				function checkform(){
					var ttitle,ttype,tsucaiid,tmsgid;
					ttitle = document.form2.ttitle.value;
					ttype = document.form2.ttype.value;
					tsucaiid = document.form2.tsucaiid.value;
					tmsgid = document.form2.tmsgid.value;
					tcontent1 = document.form2.tcontent1.value;
					tcontent5 = document.form2.tcontent5.value;
					tpath2 = document.form2.tpath2.value;
					tpath3 = document.form2.tpath3.value;
					tpath4 = document.form2.tpath4.value;
					tpath5 = document.form2.tpath5.value;
					tabstract2 = document.form2.tabstract2.value;
					tabstract3 = document.form2.tabstract3.value;
					tabstract4 = document.form2.tabstract4.value;
					tpic = document.form2.tpic.value;
					
					
					if(ttitle==""){
						alert("信息标题不能为空");
						document.form2.ttitle.focus();
						return false;
					}
					
					if(ttype==1){
						if(tcontent1==""){
							alert("请设置消息的内容");
							return false;
						}
					}else if(ttype==5){
						if(tpath5==""){
							alert("请设置消息的封面");
							return false;
						}
						if(tcontent5==""){
							alert("请设置消息的内容");
							return false;
						}
					}else if(ttype==4){
						if(tpic==""){
							alert("请设置视频的缩略图");
							return false;
						}
						if(tpath4==""){
							alert("您还未上传文件");
							return false;
						}
						if(tabstract4==""){
							alert("请设置信息的简介");
							return false;
						}
					}else if(ttype==3){
						if(tpath3==""){
							alert("您还未上传文件");
							return false;
						}
						if(tabstract3==""){
							alert("请设置信息的简介");
							return false;
						}
					}else if(ttype==2){
						if(tpath2==""){
							alert("您还未上传文件");
							return false;
						}
						if(tabstract2==""){
							alert("请设置信息的简介");
							return false;
						}
					}
					if(ttype!=1&&ttype!=5&&!(tsucaiid!=0||tmsgid!=0)){
						if(confirm("是否要保存到素材库？")){
							document.getElementById("issave").value=1;
						}
					}
					return true;
			    }
				function changeselectinfo(num){
					if(num==0){
						document.getElementById("selectinfo").innerHTML="";
					}else{
						document.getElementById("selectinfo").innerHTML="已手动选择"+num+"人";
					}
				}
				</script>
				<form id="form2" name="form2" method="post" action="?action=saveadd" onsubmit="return checkform()">
                <input type="hidden" name="ttype" id="ttype" value="1">
                <input type="hidden" name="tsucaiid" id="tsucaiid" value="0">
                <input type="hidden" name="tmsgid" id="tmsgid" value="0">
                <input type="hidden" name="issave" id="issave" value="0">
                <input type="hidden" name="filesize" id="filesize" value="0">
				  <table width="100%" border="0" align="left" cellpadding="9" cellspacing="0">
                    
                    <tr>
                      <td width="143" align="right" class="font14">发送对象：</td>
                      <td colspan="2" class="font14">
                      <select name="tgroupid">
                      <option value="0">全部用户</option>
                      <?php
                      $groupquery = $db->excu("select * from mx_user_group order by orderid,id");
					  while($grouparr = $db->fetch_array($groupquery)){
						 echo  '<option value="'.$grouparr["id"].'">'.$grouparr["groupname"].'</option>';
					  }
					  ?>
                      </select>
                      &nbsp;&nbsp;性别：<select name="tsex"><option value="2">全部</option><option value="1">男</option><option value="0">女</option></select>&nbsp;&nbsp;<input type="button" class="button2" name="button2" id="button2" value="手动选择" onclick="javascript:showdiv('list2','tsucaiid','tuisong_vpp_user','用户列表')" />&nbsp;&nbsp;<span id="selectinfo"><?php echo isset($_COOKIE["vppusersnum"])?($_COOKIE["vppusersnum"]!=0?"已手动选择".$_COOKIE["vppusersnum"]." 人":""):"";?></span></td>
                    </tr>
                    <tr>
                      <td width="143" align="right" class="font14">发送地区：</td>
                      <td colspan="2" class="font14">
                      <select name="province"></select>&nbsp;&nbsp;&nbsp;&nbsp;<select name="city"></select>&nbsp;&nbsp;&nbsp;&nbsp;<select name="area"></select></td>
                    </tr>
                    <tr>
                      <td align="right" class="font14">信息标题：</td>
                      <td colspan="2"><input type="text" name="ttitle" id="ttitle" size="70" value="" /></td>
                    </tr>
                    <script>
					new PCAS("province","city","area");
					</script>
                    <script>
					function switchmod(modtag,modtagclass1,modtagclass2,modk,modknum)
					{
						document.getElementById("ttype").value=modk;
						document.getElementById("tsucaiid").value=0;
						document.getElementById("tmsgid").value=0;
						document.getElementById("tcontent5").value="";
						document.getElementById("tcontent1").value="";
						editor.html("");
						editor2.html("");
						document.getElementById("tpath2").value="";
						document.getElementById("tpath3").value="";
						document.getElementById("tpath4").value="";
						document.getElementById("tpath5").value="";
						document.getElementById("tabstract2").value="";
						document.getElementById("tabstract3").value="";
						document.getElementById("tabstract4").value="";
						document.getElementById("tpic").value="";
						document.getElementById("showmsg").style.display="none";
						document.getElementById("showmsg2").style.display="block";
						for(i=1; i <=modknum; i++)
						{
							content=modtag+"_list"+i;
							if (i==modk)
							{
							document.getElementById(modtag+i).className=modtagclass1;
							document.getElementById(content).style.display="block";
							}
							else
							{
							document.getElementById(modtag+i).className=modtagclass2;
							document.getElementById(content).style.display="none";
							}
						}
					}
					function reurl(showid,showvalue,filesize){
						document.getElementById(showid).value=showvalue;
						document.getElementById("filesize").value=filesize;
					}
					</script>
                    <tr>
                      <td align="right" class="font14">信息类型：</td>
                      <td colspan="2">
                      <input type="button" class="button" value="文字" id="tab_1" onclick="switchmod('tab_','button','button2',1,5)">&nbsp;
                      <input type="button" class="button2" value="语音" id="tab_2" onclick="switchmod('tab_','button','button2',2,5)">&nbsp;
                      <input type="button" class="button2" value="图片" id="tab_3" onclick="switchmod('tab_','button','button2',3,5)">&nbsp;
                      <input type="button" class="button2" value="视频" id="tab_4" onclick="switchmod('tab_','button','button2',4,5)">&nbsp;
                      <input type="button" class="button2" value="图文消息" id="tab_5" onclick="switchmod('tab_','button','button2',5,5)">
                      </td>
                    </tr>
                   
                    <tr><td colspan="3" height="0">
                     <div id="tab__list1">
                    <table width="100%" border="0" align="left" cellpadding="9" cellspacing="0">
                    
                    <tr>
                      <td width="134" align="right" class="font14">信息内容：</td>
                      <td colspan="2">
                      <script charset="utf-8" src="/webedito/kindeditor-min.js"></script>
					  <script charset="utf-8" src="/webedito/lang/zh_CN.js"></script>
                      <script>
                      var editor2;
                      KindEditor.ready(function(K) {
                          editor2 = K.create('textarea[id="tcontent1"]', {
                            allowFileManager : true,
                            filterMode : false,
                            afterBlur : function() {this.sync();},

						items : ['bold','italic', 'underline', '|','insertorderedlist','insertunorderedlist','|','image','|','removeformat','forecolor','hilitecolor']
                          });
                      });
                      </script>
                      <textarea name="tcontent1" id="tcontent1" style="width:510px;height:300px;visibility:hidden;display:none;"></textarea>
                      </td>
                    </tr>
                    </table>
                    
                    </div>
                    <div id="tab__list2" style="display:none;">
                     <table width="100%" border="0" align="left" cellpadding="9" cellspacing="0">
                    <tr>
                      <td width="134" align="right" class="font14">&nbsp;</td>
                      <td colspan="2"><a href="javascript:showdiv('tab__list2','tsucaiid','tuisong_music_list','语音素材')">点击选取语音素材</a></td>
                    </tr>
                    <tr>
                      <td width="134" align="right" class="font14">语音文件：</td>
                      <td colspan="2"><button type="button" class="button1">上传</button><iframe id="uploadIframe" style="filter:alpha(opacity = 0);-moz-opacity:0;-khtml-opacity:0;opacity:0;overflow:hidden;z-index:99;position:absolute;left:170px;width:93px;height:28px;" class="uploadfile" src="sucai_upload.php?type=3&formId=1&fn=reurl&dir=sucai&label=tpath2"></iframe>&nbsp;&nbsp;<input type='text' name='tpath2'  id="tpath2" style="width:393px;" value=""></td>
                    </tr>
                    <tr>
                      <td align="right" class="font14">语音简介：</td>
                      <td colspan="2"><textarea name="tabstract2" id="tabstract2" cols="68" rows="15"></textarea></td>
                    </tr>
                    </table>
                    </div>
                    <div id="tab__list3" style="display:none;">
                     <table width="100%" border="0" align="left" cellpadding="9" cellspacing="0">
                    <tr>
                      <td width="134" align="right" class="font14">&nbsp;</td>
                      <td colspan="2"><a href="javascript:showdiv('tab__list3','tsucaiid','tuisong_pic_list','图片素材')">点击选取图片素材</a></td>
                    </tr>
                    <tr>
                      <td width="134" align="right" class="font14">图片文件：</td>
                      <td colspan="2"><button type="button" class="button1">上传</button><iframe id="uploadIframe" style="filter:alpha(opacity = 0);-moz-opacity:0;-khtml-opacity:0;opacity:0;overflow:hidden;z-index:99;position:absolute;left:170px;width:93px;height:28px;" class="uploadfile" src="sucai_upload.php?type=2&formId=1&fn=reurl&dir=sucai&label=tpath3"></iframe>&nbsp;&nbsp;<input type='text' name='tpath3'  id="tpath3" style="width:393px;" value=""></td>
                    </tr>
                    <tr>
                      <td align="right" class="font14">图片简介：</td>
                      <td colspan="2"><textarea name="tabstract3" id="tabstract3" cols="68" rows="15"></textarea></td>
                    </tr>
                    </table>
                    </div>
                    <div id="tab__list4" style="display:none;">
                     <table width="100%" border="0" align="left" cellpadding="9" cellspacing="0">
                    <tr>
                      <td width="134" align="right" class="font14">&nbsp;</td>
                      <td colspan="2"><a href="javascript:showdiv('tab__list4','tsucaiid','tuisong_video_list','视频素材')">点击选取视频素材</a></td>
                    </tr>
                    <tr>
                      <td width="134" align="right" class="font14">视频文件：</td>
                      <td colspan="2"><button type="button" class="button1">上传</button><iframe id="uploadIframe" style="filter:alpha(opacity = 0);-moz-opacity:0;-khtml-opacity:0;opacity:0;overflow:hidden;z-index:99;position:absolute;left:170px;width:93px;height:28px;" class="uploadfile" src="sucai_upload.php?type=4&formId=1&fn=reurl&dir=sucai&label=tpath4"></iframe>&nbsp;&nbsp;<input type='text' name='tpath4'  id="tpath4" style="width:393px;" value=""></td>
                    </tr>
                    <tr>
                      <td width="134" align="right" class="font14">视频缩略图：</td>
                      <td colspan="2"><button type="button" class="button1">上传</button><iframe id="uploadIframe" style="filter:alpha(opacity = 0);-moz-opacity:0;-khtml-opacity:0;opacity:0;overflow:hidden;z-index:99;position:absolute;left:170px;width:93px;height:28px;" class="uploadfile" src="sucai_upload.php?type=2&formId=1&fn=reurl&dir=sucai&label=tpic"></iframe>&nbsp;&nbsp;<input type='text' name='tpic'  id="tpic" style="width:393px;" value=""></td>
                    </tr>
                    <tr>
                      <td align="right" class="font14">视频简介：</td>
                      <td colspan="2"><textarea name="tabstract4" id="tabstract4" cols="68" rows="15"></textarea></td>
                    </tr>
                    </table>
                    </div>
                    <div id="tab__list5" style="display:none;">
                    <div id="showmsg" style="display:none;"></div>
                     <table width="100%" border="0" align="left" cellpadding="9" cellspacing="0" id="showmsg2">
                    <tr>
                      <td width="134" align="right" class="font14">&nbsp;</td>
                      <td colspan="2">
                      <a href="javascript:showdiv('showmsg','tmsgid','tuisong_msg_list','图文消息')">点击选取图文消息</a>
                      </td>
                    </tr>
                    <tr>
                      <td width="134" align="right" class="font14">图文封面：</td>
                      <td colspan="2"><button type="button" class="button1">上传</button><iframe id="uploadIframe" style="filter:alpha(opacity = 0);-moz-opacity:0;-khtml-opacity:0;opacity:0;overflow:hidden;z-index:99;position:absolute;left:170px;width:93px;height:28px;" class="uploadfile" src="sucai_upload.php?type=1&formId=1&fn=reurl&dir=sucai&label=tpath5"></iframe>&nbsp;&nbsp;<input type='text' name='tpath5'  id="tpath5" style="width:393px;" value=""></td>
                    </tr>
                    <tr>
                      <td align="right" class="font14">图文内容：</td>
                      <td colspan="2">
                      <script>
                      var editor;
                      KindEditor.ready(function(K) {
                          editor = K.create('textarea[id="tcontent5"]', {
                            allowFileManager : true,
                            filterMode : false,
                            afterBlur : function() {this.sync();},

						items : ['bold','italic', 'underline', '|','insertorderedlist','insertunorderedlist','|','image','|','removeformat','forecolor','hilitecolor']
                          });
                      });
                      </script>
                      <textarea name="tcontent5" id="tcontent5" style="width:510px;height:300px;visibility:hidden;display:none;"></textarea>
                      </td>
                    </tr>
                    </table>
                    </div>
                    </td>
                    </tr>
                    
                    <tr>
                      <td>&nbsp;</td>
                      <td class="font14" colspan="2"><input type="submit" class="button" name="button" id="button" value="完成" />&nbsp;&nbsp;
                      <input type="reset" class="button2" name="button2" id="button2" value="取消" /></td>
                    </tr>
                    <tr>
                      <td colspan="3" height="20">&nbsp;</td>
                    </tr>
                  </table>
          </form>
				<div class="height15"></div>
	  </div>
		<div class="clear"></div>
		<div class="height15"></div>
       
	  </div>
		<div class="clear"></div>
  <?php require("../mx_foot.php") ;?>
  </div>
	<!--right-end-->
</body>
</html>
